#
# /*
#  *  Copyright 2021
#  *
#  *  This program is free software: you can redistribute it and/or modify
#  *  it under the terms of the GNU General Public License as published by
#  *  the Free Software Foundation, either version 3 of the License, or
#  *  (at your option) any later version.
#  *
#  *  This program is distributed in the hope that it will be useful,
#  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  *  GNU General Public License for more details.
#  *
#  *  You should have received a copy of the GNU General Public License
#  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  *
#  * SPDX-License-Identifier: GPL-3.0+
#  * License-Filename: LICENSE
#  *
#  */
#

bin_PROGRAMS=paccgpl

paccgpl_SOURCES = \
	arg.c \
	cook.c \
	emit.c \
	error.c \
	load.c \
	main.c \
	mem.c \
	preen.c \
	sugar.c \
	syntax.c \
	template.c \
	utf8.c

#
paccgpl_CFLAGS = \
	@CFLAGS@ @PACKAGE_CFLAGS@ @WARNING_CFLAGS@
#
paccgpl_tolink = 

pacc0: $(OBJS) pacc0.o
	$(CC) $(LDFLAGS) -o $@ $^

pacc0.o: pacc0.c syntax.h

pacc1: $(OBJS) pacc1.o
	$(CC) $(LDFLAGS) -o $@ $^

pacc1.c: pacc0
	./pacc0 -n pacc /dev/null -o $@

pacc2: $(OBJS) pacc2.o
	$(CC) $(LDFLAGS) -o $@ $^

pacc2.c: pacc1 pacc.pacc
	./pacc1 pacc.pacc -o $@

pacc3: $(OBJS) pacc3.o
	$(CC) $(LDFLAGS) -o $@ $^

pacc3.c: pacc2 pacc.pacc
	./pacc2 pacc.pacc -o $@

pacc: pacc2.d pacc3.d
	diff -u $^
	cp pacc2 $@

template.c: pacc.tmpl template.sh
	sh template.sh > $@

%.d: %.c
	sed '/^#line/d' $^ > $@

boot: boot.o error.o load.o pacc2.o syntax.o utf8.o
	$(CC) $(LDFLAGS) -o $@ $^

#
paccgpl$(EXEEXT): $(paccgpl_SOURCES)
	rm -f ./paccgpl
	$(CC) $(paccgpl_CFLAGS) $(paccgpl_SOURCES) pacc0.c -I. -I.. $(paccgpl_tolink) -lm -o paccgpl
	$(CC) --version

#
indent:
	./lindent.sh $(packgpl_SOURCES) arg.h cook.h emit.h error.h load.h mem.h preen.h sugar.h syntax.h template.h utf8.h

#
clean-generic:
	rm -v -f *.bc
	rm -v -f ./massif.out.*
	rm -v -f ./a.out
	rm -v -f *~
	rm -v -f ./*.so.1
	rm -v -f ./*.o
	rm -v -f ./*.a
	rm -v -f ./*.i
	rm -v -f ./*.s
	rm -v -f ./O
	rm -v -f ./OO
	rm -v -f ./O1
	rm -v -f ./O2
	rm -v -f ./O3
	rm -v -f ./ID
	rm -v -f ./dsmake.output
	rm -v -f ./dsmake.warnings
	rm -v -f ./dsmake.errors
	rm -v -f *.dot
	rm -v -f *.*r.*
	rm -v -f *.*t.*
	rm -v -f *.bc
	rm -v -f *.plist
	rm -v -f *.ps
	rm -v -f ./*.exe
	rm -v -f jsonlint
	rm -v -f ./*.gk*
	rm -v -f ./*.out
	rm -v -f ./*.res
	rm -v -f *.scallgraph.gv
	rm -v -f -r .deps
	rm -v -f *graph-info.gv
	rm -v -f *graph-info.svg
	rm -v -f *graph-info.ci
	rm -v -f *.ci
	rm -v -f paccgpl

# /* end. */
